package com.dtagri.fjwlw.adapter;

import java.util.Date;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.dtagri.fjwlw.R;
import com.dtagri.fjwlw.base.ListBaseAdapter;
import com.dtagri.fjwlw.bean.TjData;
import com.dtagri.fjwlw.util.StringUtils;

/**
 * @author wxjn
 * 
 */
public class HistoricalDataAdapter extends ListBaseAdapter<TjData> {

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	private String key = "";

	@Override
	protected View getRealView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh = null;
		if (convertView == null || convertView.getTag() == null) {
			convertView = getLayoutInflater(parent.getContext()).inflate(
					R.layout.list_cell_historical_data, null);
			vh = new ViewHolder(convertView);
			convertView.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}

		vh.historicalKey.setText(key + "");
		vh.historicalValue.setText(mDatas.get(position).getValue()
				+ mDatas.get(position).getUnit());
		Date retime = mDatas.get(position).getRetime();
		vh.historicalDate.setText(StringUtils.dateToString(retime));
		return convertView;
	}

	static class ViewHolder {
		@InjectView(R.id.tv_historical_key)
		TextView historicalKey;
		@InjectView(R.id.tv_historical_value)
		TextView historicalValue;
		@InjectView(R.id.tv_historical_date)
		TextView historicalDate;

		public ViewHolder(View view) {
			ButterKnife.inject(this, view);
		}
	}
}
